var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
      userID: null,
      nickname: null,
      avatar: null,
      sex: null,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      this.setData({ userID: options.uid });
      if (options.action) this.setData({ action: options.action });  
      if (options.group_id) this.setData({ group_id: options.group_id });      
      this.getUserInfo();
    },

    getUserInfo: function() {
        var that = this;
        wx.request({
          url: app.buildUrl('/user/info'),
          header: app.getRequestHeader(),
          data: {
              uid: that.data.userID
          },
          success: function(res) {
            var resp = res.data;
            if (resp.code != 200) {
                app.alert({
                  "content": resp.msg
                });
                return;
            }
            var user_info = resp.data.user_info;
            var sex;
            if (user_info.sex == '0') sex = '男';
            else if(user_info.sex  == '1') sex = '女';
            else sex = '未知';
            that.setData({
                nickname: user_info.nickname,
                avatar: user_info.avatar,
                sex: sex
            });
          }
        })
    },

    invite: function() {
        var that = this;
        app.alert({
            "content": "确定要邀请该用户吗",
            "showCancel": true,
            "cb_confirm": function() {
                wx.request({
                  url: app.buildUrl('/group/invite-member'),
                  header: app.getRequestHeader(),
                  data: {
                      user_id: that.data.userID,
                      group_id: that.data.group_id
                  },
                  success: function(res) {
                    var resp = res.data;
                    app.alert({
                        "content": resp.msg
                    });
                    if (resp.code == 200) {
                        setTimeout(function () {
                            wx.switchTab({
                                url: '/pages/function/function'
                            });
                        }, 1000);
                    }
                  }
                })
            },
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})